package com.winsdom.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.winsdom.dto.UnclearedDTO;
import com.winsdom.dto.resource.BillsPageQueryReqDTO;
import com.winsdom.result.PageResult;
import com.winsdom.result.Result;
import com.winsdom.service.IBillsService;
import com.winsdom.vo.BillDetailsVO;
import com.winsdom.vo.resource.BillsNotArrearsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 账单表 前端控制器
 * </p>
 *
 * @author 
 * @since 2025-05-22
 */
@Slf4j
@RestController
@RequestMapping("/bills")
@Api(tags = "账单管理相关接口")
public class BillsController {
    @Autowired
    private IBillsService billsService;

    /**
     * 获取未结清单
     * @param unclearedDTO 查询条件
     * @return 未结清单列表
     */
    @PostMapping("/uncleared")
    @ApiOperation("获取未结清单")
    public Result<PageResult> getUnclearedBills(@Valid @RequestBody UnclearedDTO unclearedDTO) {
        log.info("获取未结清单：{}",  unclearedDTO);
        PageResult pageResult = billsService.getUnclearedBills(unclearedDTO);

        return Result.success(pageResult);
    }

    /**
     * 查询已缴费账单
     *
     * @param billsPageQueryReqDTO 查询条件
     * @return 已缴费账单列表
     * @param pageNum
     * @param pageSize
     * @param billsPageQueryReqDTO
     * @return
     */
    @PostMapping("/selectArrearsListForParams")
    @ApiOperation(value = "查询已结清账单")
    public PageResult selectArrearsListForParams(@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
                                                 @Parameter(description = "每页条数") @RequestParam(defaultValue = "10") Integer pageSize,
                                                 @RequestBody BillsPageQueryReqDTO billsPageQueryReqDTO){
        log.info("条件查询操作日志列表,页码：{}，每页条数：{}，查询条件：{}",pageNum,pageSize,billsPageQueryReqDTO);
        Page<BillsNotArrearsVO> page = billsService.selectArrearsListForParams(pageNum,pageSize,billsPageQueryReqDTO);
        return new PageResult(page.getTotal(),page.getRecords(),pageNum,pageSize);
    }

    @GetMapping("/Billdetails")
    @ApiOperation(value = "账单详情")
    public Result<BillDetailsVO> BillDetails(@Valid @RequestParam Long billsId){
        log.info("账单详情：{}", billsId);
        return Result.success(billsService.getBillDetails(billsId));
    }


}
